package com.seveneight.baijiesteward.ui.first.model;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.bean.MenuBean;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.http.XObserver;
import com.seveneight.baijiesteward.ui.first.contract.FirstMenuContract;

import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/21.
 */

public class FirstMenuModel extends BaseModel implements FirstMenuContract.MenuModel {

    @Override
    public void getFirstMenu( RequestBody body, MyCallBack<List<MenuBean>> myCallBack) {
        RetrofitFactory.getInstence().API()
                .getFirstMenu(body)
                .compose((this.<BaseEntity<AnyBean>>setThread()))
                .subscribe(new XObserver<AnyBean>() {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        List<MenuBean> data= JSON.parseArray(t.getData().getMenuData(),MenuBean.class);
                        myCallBack.onSuccess(data);
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
